//
//  FinderListModel.m
//
//  Created by   on 2019/6/4
//  Copyright (c) 2019 __MyCompanyName__. All rights reserved.
//

#import "FinderListModel.h"


NSString *const kFinderListModelId = @"id";
NSString *const kFinderListModelArticleTitle = @"articleTitle";
NSString *const kFinderListModelArticleContet = @"articleContet";
NSString *const kFinderListModelArticleStatus = @"articleStatus";
NSString *const kFinderListModelDelete = @"delete";
NSString *const kFinderListModelIsDelete = @"isDelete";
NSString *const kFinderListModelCollectionCount = @"collectionCount";
NSString *const kFinderListModelAddUser = @"addUser";
NSString *const kFinderListModelArticleType = @"articleType";
NSString *const kFinderListModelAddTime = @"addTime";
NSString *const kFinderListModelTopCount = @"topCount";
NSString *const kFinderListModelSmallImage = @"smallImage";
NSString *const kFinderListModelUpdateUser = @"updateUser";
NSString *const kFinderListModelUpdateTime = @"updateTime";


@interface FinderListModel ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation FinderListModel

@synthesize internalBaseClassIdentifier = _internalBaseClassIdentifier;
@synthesize articleTitle = _articleTitle;
@synthesize articleContet = _articleContet;
@synthesize articleStatus = _articleStatus;
@synthesize delete = _delete;
@synthesize isDelete = _isDelete;
@synthesize collectionCount = _collectionCount;
@synthesize addUser = _addUser;
@synthesize articleType = _articleType;
@synthesize addTime = _addTime;
@synthesize topCount = _topCount;
@synthesize smallImage = _smallImage;
@synthesize updateUser = _updateUser;
@synthesize updateTime = _updateTime;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.internalBaseClassIdentifier = [[self objectOrNilForKey:kFinderListModelId fromDictionary:dict] doubleValue];
            self.articleTitle = [self objectOrNilForKey:kFinderListModelArticleTitle fromDictionary:dict];
            self.articleContet = [self objectOrNilForKey:kFinderListModelArticleContet fromDictionary:dict];
            self.articleStatus = [[self objectOrNilForKey:kFinderListModelArticleStatus fromDictionary:dict] boolValue];
            self.delete = [[self objectOrNilForKey:kFinderListModelDelete fromDictionary:dict] boolValue];
            self.isDelete = [[self objectOrNilForKey:kFinderListModelIsDelete fromDictionary:dict] boolValue];
            self.collectionCount = [[self objectOrNilForKey:kFinderListModelCollectionCount fromDictionary:dict] doubleValue];
            self.addUser = [self objectOrNilForKey:kFinderListModelAddUser fromDictionary:dict];
            self.articleType = [self objectOrNilForKey:kFinderListModelArticleType fromDictionary:dict];
            self.addTime = [[self objectOrNilForKey:kFinderListModelAddTime fromDictionary:dict] doubleValue];
            self.topCount = [[self objectOrNilForKey:kFinderListModelTopCount fromDictionary:dict] doubleValue];
            self.smallImage = [self objectOrNilForKey:kFinderListModelSmallImage fromDictionary:dict];
            self.updateUser = [self objectOrNilForKey:kFinderListModelUpdateUser fromDictionary:dict];
            self.updateTime = [[self objectOrNilForKey:kFinderListModelUpdateTime fromDictionary:dict] doubleValue];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithDouble:self.internalBaseClassIdentifier] forKey:kFinderListModelId];
    [mutableDict setValue:self.articleTitle forKey:kFinderListModelArticleTitle];
    [mutableDict setValue:self.articleContet forKey:kFinderListModelArticleContet];
    [mutableDict setValue:[NSNumber numberWithBool:self.articleStatus] forKey:kFinderListModelArticleStatus];
    [mutableDict setValue:[NSNumber numberWithBool:self.delete] forKey:kFinderListModelDelete];
    [mutableDict setValue:[NSNumber numberWithBool:self.isDelete] forKey:kFinderListModelIsDelete];
    [mutableDict setValue:[NSNumber numberWithDouble:self.collectionCount] forKey:kFinderListModelCollectionCount];
    [mutableDict setValue:self.addUser forKey:kFinderListModelAddUser];
    [mutableDict setValue:self.articleType forKey:kFinderListModelArticleType];
    [mutableDict setValue:[NSNumber numberWithDouble:self.addTime] forKey:kFinderListModelAddTime];
    [mutableDict setValue:[NSNumber numberWithDouble:self.topCount] forKey:kFinderListModelTopCount];
    [mutableDict setValue:self.smallImage forKey:kFinderListModelSmallImage];
    [mutableDict setValue:self.updateUser forKey:kFinderListModelUpdateUser];
    [mutableDict setValue:[NSNumber numberWithDouble:self.updateTime] forKey:kFinderListModelUpdateTime];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.internalBaseClassIdentifier = [aDecoder decodeDoubleForKey:kFinderListModelId];
    self.articleTitle = [aDecoder decodeObjectForKey:kFinderListModelArticleTitle];
    self.articleContet = [aDecoder decodeObjectForKey:kFinderListModelArticleContet];
    self.articleStatus = [aDecoder decodeBoolForKey:kFinderListModelArticleStatus];
    self.delete = [aDecoder decodeBoolForKey:kFinderListModelDelete];
    self.isDelete = [aDecoder decodeBoolForKey:kFinderListModelIsDelete];
    self.collectionCount = [aDecoder decodeDoubleForKey:kFinderListModelCollectionCount];
    self.addUser = [aDecoder decodeObjectForKey:kFinderListModelAddUser];
    self.articleType = [aDecoder decodeObjectForKey:kFinderListModelArticleType];
    self.addTime = [aDecoder decodeDoubleForKey:kFinderListModelAddTime];
    self.topCount = [aDecoder decodeDoubleForKey:kFinderListModelTopCount];
    self.smallImage = [aDecoder decodeObjectForKey:kFinderListModelSmallImage];
    self.updateUser = [aDecoder decodeObjectForKey:kFinderListModelUpdateUser];
    self.updateTime = [aDecoder decodeDoubleForKey:kFinderListModelUpdateTime];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeDouble:_internalBaseClassIdentifier forKey:kFinderListModelId];
    [aCoder encodeObject:_articleTitle forKey:kFinderListModelArticleTitle];
    [aCoder encodeObject:_articleContet forKey:kFinderListModelArticleContet];
    [aCoder encodeBool:_articleStatus forKey:kFinderListModelArticleStatus];
    [aCoder encodeBool:_delete forKey:kFinderListModelDelete];
    [aCoder encodeBool:_isDelete forKey:kFinderListModelIsDelete];
    [aCoder encodeDouble:_collectionCount forKey:kFinderListModelCollectionCount];
    [aCoder encodeObject:_addUser forKey:kFinderListModelAddUser];
    [aCoder encodeObject:_articleType forKey:kFinderListModelArticleType];
    [aCoder encodeDouble:_addTime forKey:kFinderListModelAddTime];
    [aCoder encodeDouble:_topCount forKey:kFinderListModelTopCount];
    [aCoder encodeObject:_smallImage forKey:kFinderListModelSmallImage];
    [aCoder encodeObject:_updateUser forKey:kFinderListModelUpdateUser];
    [aCoder encodeDouble:_updateTime forKey:kFinderListModelUpdateTime];
}

- (id)copyWithZone:(NSZone *)zone
{
    FinderListModel *copy = [[FinderListModel alloc] init];
    
    if (copy) {

        copy.internalBaseClassIdentifier = self.internalBaseClassIdentifier;
        copy.articleTitle = [self.articleTitle copyWithZone:zone];
        copy.articleContet = [self.articleContet copyWithZone:zone];
        copy.articleStatus = self.articleStatus;
        copy.delete = self.delete;
        copy.isDelete = self.isDelete;
        copy.collectionCount = self.collectionCount;
        copy.addUser = [self.addUser copyWithZone:zone];
        copy.articleType = [self.articleType copyWithZone:zone];
        copy.addTime = self.addTime;
        copy.topCount = self.topCount;
        copy.smallImage = [self.smallImage copyWithZone:zone];
        copy.updateUser = [self.updateUser copyWithZone:zone];
        copy.updateTime = self.updateTime;
    }
    
    return copy;
}


@end
